#
#
# import datetime
# import decimal
# import uuid
#
# from flask.json.provider import DefaultJSONProvider
#
# from flask_sqlalchemy import SQLAlchemy
#
# db = SQLAlchemy()
#
# class JSONEncoder(DefaultJSONProvider):
#     def default(self, o):
#         if isinstance(o, datetime.datetime):
#             # 格式化日期
#             return o.strftime("%Y-%m-%d %H:%M:%S")
#         if isinstance(o, datetime.date):
#             # 格式化时间
#             return o.strftime("%Y-%m-%d")
#         if isinstance(o, decimal.Decimal):
#             # 格式化高精度数字
#             return str(o)
#         if isinstance(o, uuid.UUID):
#             # 格式化uuid
#             return str(o)
#         if isinstance(o, bytes):
#             # 格式化字节数据
#             return o.decode("utf-8")
#         return super(JSONEncoder, self).default(o)
#
#
# import datetime
# import decimal
# import uuid
#
# from flask.json import JSONEncoder as BaseJSONEncoder
# from flask_sqlalchemy import SQLAlchemy
#
# db = SQLAlchemy()
#
# class JSONEncoder(BaseJSONEncoder):
#     def default(self, o):
#         if isinstance(o, datetime.datetime):
#             # 格式化日期
#             return o.strftime("%Y-%m-%d %H:%M:%S")
#         if isinstance(o, datetime.date):
#             # 格式化时间
#             return o.strftime("%Y-%m-%d")
#         if isinstance(o, decimal.Decimal):
#             # 格式化高精度数字
#             return str(o)
#         if isinstance(o, uuid.UUID):
#             # 格式化uuid
#             return str(o)
#         if isinstance(o, bytes):
#             # 格式化字节数据
#             return o.decode("utf-8")
#         return super(JSONEncoder, self).default(o)

import datetime
import decimal
import uuid
import json
from flask import Flask
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

class JSONEncoder(json.JSONEncoder):
    def default(self, o):
        if isinstance(o, datetime.datetime):
            # 格式化日期时间
            return o.strftime("%Y-%m-%d %H:%M:%S")
        if isinstance(o, datetime.date):
            # 格式化日期
            return o.strftime("%Y-%m-%d")
        if isinstance(o, decimal.Decimal):
            # 格式化高精度数字
            return str(o)
        if isinstance(o, uuid.UUID):
            # 格式化 UUID
            return str(o)
        if isinstance(o, bytes):
            # 格式化字节数据
            return o.decode("utf-8")
        return super(JSONEncoder, self).default(o)

# 使用自定义的 JSONEncoder
app = Flask(__name__)
app.json_encoder = JSONEncoder